import 'package:example/config/web_config.dart';
import 'package:get/get.dart';
import '../main.dart';
import '../utils/common.dart';
import '../view/error/page_not_found/page_not_found_view.dart';
import '../view/home/home_view.dart';
import '../view/main/main_binding.dart';
import '../view/main/main_view.dart';
import '../view/mine/mine_view.dart';


class RouteConfig {
  /// 主页面 禁止使用/作为跟路径 会导致重定向异常
  static const String main = "/main";
  static const String myApp = "/myApp";

  /// 登录
  static const String login = "/login";

  /// webView页
  static const String previewWebView = "/preview/webView";

  /// 预览图片
  static const String previewImage = "/preview/image";

  /// 页面不存在异常页
  static const String pageNotFoundError = "/pageNotFoundError";

  /// 首页
  static const String homePage = "/HomePage";
  /// 我的
  static const String minePage = "/MinePage";


  /// 别名映射页面
  static final List<GetPage> getPages = [
    GetPage(
      name: main,
      page: () => MainPage(),
      binding: MainBinding(),
      parameters: const {"title": "主页"},
    ),
    GetPage(
      name: myApp,
      page: () => const MyApp(),
      parameters: const {"title": ""},
    ),
    GetPage(
      name: homePage,
      page: () => HomePage(),
      parameters: const {"title": "首页"},
    ),
    GetPage(
      name: minePage,
      page: () => MinePage(),
      parameters: const {"title": "我的"},
    ),
  ];

  /// 基础跳转
  ///
  /// url 跳转路径
  /// isWeb 是否web页面
  /// params 路径参数
  /// arguments 跳转参数
  static Future<T?>? toUrl<T>(
    String? url, {
    isWeb = false,
    dynamic params,
    dynamic arguments,
  }) {
    if (isNotEmptyOrNull(url)) {
      // web跳转
      if (isWeb) {
        return WebConfig.toUniversalUrl<T>(url!,
            params: params, arguments: arguments);
      } else {
        // 原生跳转
        return Get.toNamed<T>(url!, arguments: arguments);
      }
    } else {
      return Future.error("跳转失败");
    }
  }
}
